<template>
  <el-row class="top">
    <el-col class="titleName" :class="title === '化工产业大脑'?'titleName1':''">{{title}}
      <div style="position: absolute;font-weight: 500;font-size: 22px;color: #BBDAFF;top: 0;left: 20px;">
        <img src="../assets/img/lclb/LOGO.png" width="40" height="40" alt=""/>
        数字经济综合应用
      </div>
      <div style="position: absolute;font-size: 16px;font-weight: 500;color: #BBDAFF;top: 0;right: 20px;">
        <i v-if="title !== '化工产业大脑'" class="el-icon-s-home" @click="goHome()"></i>
        {{ nowDate }}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <span v-if="zfName !== null && zfName !== undefined && zfName !== ''">你好，{{zfName}}</span>
        <span v-else>你好</span>
      </div>
    </el-col>
  </el-row>
</template>
<script>
// import dd from 'gdt-jsapi';
export default {
  props: {
    title: {
      title: '',
      type: String
    }
  },
  data () {
    return {
      nowDate: '',
      zfName: sessionStorage.getItem('zfName')
    }
  },
  watch: {
    '$store.state.user.zfName': function () {
      this.$nextTick(() => {
        this.zfName = this.$store.state.user.zfName
        sessionStorage.setItem('zfName',this.$store.state.user.zfName)
      })
    }
  },
  created () {
    // dd.getAuthCode({}).then(res =>{
    //   if (res) {
    //     let params = {
    //       applicationFlag: '20',
    //       authCode: res.auth_code
    //     }
    //     this.$http.post(`/home/sys/loginfree/authentication`, params)
    //       .then(({ data: res }) => {
    //         console.log('res2:',res);
    //         this.$store.commit('zfName', res.data.lastName)
    //         if (res.code !== 0) {
    //           this.$emit('zfNameflag',false)
    //         }
    //       }).catch(() => {
    //         this.$emit('zfNameflag',false)
    //       })
    //   }
    // }).catch(() => {
    //   this.$emit('zfNameflag',false)
    // })
    let date = new Date()
    this.nowDate = this.getDateTime(date)
  },
  methods: {
    getDateTime (value) {
      let now = new Date(value)
      let year = now.getFullYear() // 年
      let month = now.getMonth() + 1 // 月
      let day = now.getDate() // 日
      let hour = now.getHours() // 时
      let minutes = now.getMinutes() // 分
      let seconds = now.getSeconds() // 秒
      let clock = year + '-'
      if (month < 10) clock += '0'
      clock += month + '-'
      if (day < 10) clock += '0'
      // clock += day
      clock += day + ' '
      if (hour < 10) clock += '0'
      clock += hour + ':'
      if (minutes < 10) clock += '0'
      clock += minutes + ':'
      if (seconds < 10) clock += '0'
      clock += seconds
      return clock
    },
    goHome(){
      this.$router.push({
        name: 'home'
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.top {
  height: 74px;
  line-height: 74px;
  box-sizing: border-box;
  color: rgb(115, 188, 235);
  background-image: url("../assets/img/zf/top_bg2.png");
  background-size: 100% 100%;
}
.titleName{
  font-size: 24px;
  font-weight: 600;
  text-align: center;
  position: relative;
}
.titleName1{
  font-size: 32px;
}
.el-icon-s-home{
  font-size: 20px;
  cursor: pointer;
}
</style>
